package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.impl.UserBizImpl;

@WebServlet("/usersearch.json")
public class SearchUserServlet extends HttpServlet{

	private UserBizImpl ubiz = new UserBizImpl();
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		resp.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		
		int startAge = Integer.parseInt(
				(req.getParameter("startAge") == null || 
				req.getParameter("startAge").equals("")) ? "-1"
						: req.getParameter("startAge"));
		int endAge = Integer
				.parseInt((req.getParameter("endAge") == null || 
				req.getParameter("endAge").equals("")) ? "-1"
						: req.getParameter("endAge"));
		
		String sex = req.getParameter("sex");
		
		String address = req.getParameter("address");
		address=address.replace("10", "");
		
		System.out.println(name+"\t"+startAge+"\t"+endAge+"\t"+sex+"\t"+address);
		
		PrintWriter out = resp.getWriter();
		out.println(ubiz.findSearchUser(name, startAge, endAge, sex, address));
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
